<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CouponOrderDataEdit extends Migrator
{
    public function up()
    {
        //把聚推客的supplier_code 赋值一下

        $supplierObj = \app\model\BaseSupplier::query()->where('code','jutuike')->find();
        $supplierids = \app\model\BaseSupplier::query()->where('code','jutuike')->column('id');
        if ($supplierObj){
            $datas = \app\model\CouponOrder::query()
                ->whereIn('supplier_id',$supplierids)
                ->select();

            foreach ($datas as $order) {
                /**
                 * @var \app\model\CouponOrder $order
                 */

                if (empty($order->supplier_code)){
                    $order->supplier_code = $supplierObj->code;
                    $order->save();
                }
            }


        }

    }
    public function down()
    {

        $supplierObj = \app\model\BaseSupplier::query()
            ->where('code','jutuike')
            ->find();
        $supplierids = \app\model\BaseSupplier::query()->where('code','jutuike')->column('id');
        if ($supplierObj){
            $datas = \app\model\CouponOrder::query()
                ->whereIn('supplier_id',$supplierids)
                ->select();

            foreach ($datas as $order) {
                /**
                 * @var \app\model\CouponOrder $order
                 */

                if (!empty($order->supplier_code)){
                    $order->supplier_code = '';
                    $order->save();
                }
            }


        }
    }
}
